package com.tt.dp.component;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Menu extends MenuComponent {

    private List<MenuComponent> components = new ArrayList<MenuComponent>();

    private String name;

    private String description;

    public Menu(String name, String description) {
        this.name = name;
        this.description = description;
    }

    @Override
    public void add(MenuComponent component) {
        this.components.add(component);
    }

    @Override
    public void remove(MenuComponent component) {
        this.components.remove(component);
    }

    @Override
    public MenuComponent getChild(int index) {
        return this.components.get(index);
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public String getDescription() {
        return description;
    }

    @Override
    public Iterator createIterator() {
        return new CompositeIterator(this.components.iterator());
    }

    @Override
    public void print() {
        System.out.print("\n" + getName());
        System.out.println(", " + getDescription());
        System.out.println("---------------------");

        Iterator<MenuComponent> it = this.components.iterator();

        while (it.hasNext()) {
            MenuComponent item = it.next();
            item.print();
        }
    }
}
